package com.navinfo.platform.trip.analysis.service.impl.dongfeng;

import com.navinfo.platform.trip.common.annotation.SystemType;
import com.navinfo.platform.trip.common.enums.SystemTypeEnum;
import com.navinfo.platform.trip.analysis.service.TripJudgeService;
import com.navinfo.platform.trip.common.pojo.PointProtocol;
import com.navinfo.platform.trip.common.enums.TripStatusEnum;
import com.navinfo.platform.trip.analysis.pojo.TripJudgeState;
import static com.navinfo.platform.trip.common.enums.TripStatusEnum.*;

/**
 * 东风行程切分服务
 * 行程第一个点：速度>0且acc=on：行程开始；否则，行程未开始；
 * 行程非第一个点：
 *      两点时差大于10分钟：行程强制结束，
 *      两点时差小于十分钟：（速度=0且acc=off 或 位置点个数>5000），行程结束；否则，行程进行中；
 *
 * @author: web
 * @data : 2020-04-07
 **/
@SystemType(value= SystemTypeEnum.DF, interfaceClass= TripJudgeService.class )
public class TripJudgeServiceImpl implements TripJudgeService {
    /**
     * 速度阈值
     */
    private static final long SPEED_THRESHOLD = 0;
    /**
     * 0200位置点个数阈值
     */
    private static final long COUNT_THRESHOLD = 5000;

    @Override
    public SystemTypeEnum systemType() {
        return SystemTypeEnum.DF;
    }

    @Override
    public TripStatusEnum tripStatus(TripJudgeState tripJudgeState, PointProtocol point) {

        //行程未开始
        if (null==tripJudgeState || null==tripJudgeState.getLastGpsTime()) {
            return (point.getAccStatus()==1 && point.getSpeedKmh()>SPEED_THRESHOLD) ? TRIP_START : TRIP_NO_START;
        }

        //行程已开始
        else {
            if (isForceEnd(tripJudgeState.getLastGpsTime(), point.getGpsTime())) {
                return TRIP_FORCE_END;
            } else {
                //行程结束：(acc=off && 速度 = 0) ||  位置点个数>5000
                return ((point.getAccStatus()==0 && point.getSpeedKmh()==SPEED_THRESHOLD) || tripJudgeState.getCount0200()>COUNT_THRESHOLD) ? TRIP_END : TRIP_IN;
            }
        }
    }

}
